package projet.metier;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import projet.metier.ThreadInterface;

/**
 * Main class, define the main method.
 * @author Ambroise
 */
public class Main {

	/**
	 * Main method, lauch the software.
	 * 
	 * @param args - array - Params.
	 */
	public static void main(String[] args) {
		// On crée une liste (un pool) destinée à contenir nos threads.
				List<Runnable> threads = new ArrayList<Runnable>();
				
				// On ajoute notre fenêtre principale comme étant un thread dans ce pool.
				threads.add(new ThreadInterface());

				// On crée un pool pouvant utiliser autant de threads qu'il y a de processeurs.
				ExecutorService execute = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
				
				executeRunnables(execute, threads);

	}
	
	/**
	 * Static method, execute all runnables elements received.
	 * 
	 * @param service - ExecutorService - Executor.
	 * @param runnables - List<Runnable> - Threads to run.
	 */
	public static void executeRunnables(final ExecutorService service, List<Runnable> runnables){
        //On exécute chaque "Runnable" de la liste "runnables"
		for(Runnable threads : runnables){
		
			service.execute(threads);
		}
		service.shutdown();
	}

}
